{% extends "layout.html" %}

{% block title %}部署管理{% endblock %}

{% block css %}
	{{super()}}
	<link href="{{ url_for('static',filename='libs/jeasyui/themes/icon.css') }}" rel="stylesheet" type="text/css" />
	<link href="{{ url_for('static',filename='libs/jeasyui/themes/default/easyui.css') }}" rel="stylesheet" type="text/css" />
{% endblock %}


{% block clientscript %}
	{{super()}}
	<script src="{{ url_for('static',filename='js/page.js') }}"></script>
	<script src="{{ url_for('static',filename='libs/jeasyui/jquery.easyui.min.js') }}"></script>
	<script src="{{ url_for('static',filename='libs/jeasyui/locale/easyui-lang-zh_CN.js') }}"></script>
	<script>
		function edit_deploy(id) {
		    $('#dlg').dialog({
						title: '部署编辑',
						width: 500,
						height: 435,
						closed: false,
						cache: false,
						modal: true
					});
				   $('#dlg').dialog('refresh','/edit_deploy/{{repos_id}}'+(id?'/'+id:''));
		}
		
		function del_deploy(id) {
         $.messager.confirm("确认", "确定要删除该部署设置吗?", function (r) {
                if (r) {
                    $.post("/del_deploy/"+id,function(data,status){
                    		if (data=='1') {
                    			$('#gri').datagrid('reload');
                    		} else {
                    			alert(data);
                    		}
                    });
                }
            });
		}
		
	   function do_deploy(id) {
         $.messager.confirm("确认", "确定要立即发布当前分枝吗?", function (r) {
                if (r) {
                    $.post("/do_deploy/"+id,function(data,status){
                    		if (data=='1') {
                    			$('#gri').datagrid('reload');
                    		} else {
                    			alert(data);
                    		}
                    });
                }
            });
	   }
	   
		function op_fmt(val,row) {
		   if (row.deploy_status=='1') {
				return '[<a href="javascript:void(0)" onclick="edit_deploy('+row.id+')">编辑</a>]&nbsp;&nbsp;'+
						 '[<a href="javascript:void(0)" onclick="del_deploy('+row.id+')">删除</a>]&nbsp;&nbsp;'+
						 '[<a href="javascript:void(0)" onclick="do_deploy('+row.id+')">发布</a>]';
		   }else {
		   	return row.deploy_status;
		   }
		}
	</script>
{% endblock clientscript %}

{% block body %}
	 <div id="tb" style="padding:3px">
       <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="edit_deploy()">添加部署</a>
    </div>
    {% from "snippet.html" import render_field %}
    <div id="dlg" closed="true" class="easyui-dialog" data-options="buttons: [{
            text:'确定',
            iconCls:'icon-ok',
            handler:function(){
                $.ajax({
                    type: 'post',
                    url: $('#form_post').attr('action'),
                    data:$('#form_post').serialize(),
                    dataType: 'text',
                    success: function(data,textStatus){
                        if (data=='1'){
                            $('#gri').datagrid('reload');
                            $('#dlg').dialog('close');
                        } else {
                            $.messager.alert('错误',data,'error');
                        }

                    },
                    error: function(err){
                        //请求出错处理
                        $.messager.alert('错误','操作失败,请稍后重试!','error');
                    }
                });
            }
        },{

            text:'取消',
            iconCls:'icon-cancel',
            handler:function(){
                $('#dlg').dialog('close');
            }
        }]">
    </div>

    <div class='grid'>
	    <table id="gri" class="easyui-datagrid" style="height:470px;width:760px"
	            url="{{ url_for('qry_deploy_data',repos_id=repos_id) }}"
	            title=""
	            toolbar="#tb"
	            singleSelect="true"
	            pageSize="20"
	            fitColumns="true"
	            rownumbers="true" pagination="true">
	        <thead>
	            <tr>
	                <th field="branch" width="20">分枝</th>
	                <th field="deploy_servers" width="30">服务器</th>
						 <th field="deploy_path" width="20">部署路径</th>
						 <th field="op" formatter="op_fmt" width="30">操作</th>
	            </tr>
	        </thead>
	    </table>
    </div>
{% endblock body %}